﻿using System;
using System.Globalization;
using System.Windows.Data;
using OpenCvSharp;
using System.ComponentModel;

namespace Xc.Logics.CodeReaders.Models
{
    [TypeConverter(typeof(MatTypeConverter))]
    public class MatTypeConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var text = value?.ToString();
            return text;

        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var info = typeof(MatType).GetField(value?.ToString(), System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.CreateInstance);
            if (info == null)
            {
                return MatType.CV_32FC3;
            }
            var d = info.GetValue(Activator.CreateInstance(typeof(MatType)));
            return d;
        }
    }
}
